package com.kkd.kkdapp.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.kkd.kkdapp.R;
import com.kkd.kkdapp.http.entity.CardItem;
import com.nostra13.universalimageloader.core.ImageLoader;

public class CardTypeAdapter extends BaseAdapter {

	private List<CardItem> mList;
	private Context context;

	public CardTypeAdapter(Context context, List<CardItem> mList) {
		this.mList = mList;
		this.context = context;
	}

	class ViewHodler {
		ImageView bank_img;
		ImageView iv_right;
		TextView bank_tv;
		TextView tv_desc;
	}

	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHodler hodler;
		if (convertView == null) {
			hodler = new ViewHodler();
			convertView = View.inflate(context, R.layout.cardtype_item, null);
			hodler.bank_img = (ImageView) convertView
					.findViewById(R.id.bank_img);
			hodler.iv_right = (ImageView) convertView
					.findViewById(R.id.iv_right);
			hodler.bank_tv = (TextView) convertView.findViewById(R.id.bank_tv);
			hodler.tv_desc = (TextView) convertView.findViewById(R.id.tv_desc);

			convertView.setTag(hodler);
		} else {
			hodler = (ViewHodler) convertView.getTag();
		}

		ImageLoader.getInstance().displayImage(
				mList.get(position).getImageUrl(), hodler.bank_img,
				R.drawable.mybank_default);
		hodler.bank_tv.setText(mList.get(position).getBankName());
		hodler.tv_desc.setText(mList.get(position).getLimitEach() + "  "
				+ mList.get(position).getLimitDay());
		hodler.iv_right
				.setVisibility(mList.get(position).isClick() ? View.VISIBLE
						: View.GONE);
		return convertView;
	}

}
